package com.renting.modules.sys.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.renting.common.utils.Constant;
import com.renting.modules.sys.dao.MenuDao;
import com.renting.modules.sys.entity.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by Administrator on 2018/4/9.
 */
@Service
public class MenuService {
    @Autowired
    MenuDao menuDao;

    public List<Menu> findAll(Menu menu) {
        List<Menu> menuList = new ArrayList<>();
        Iterator<Menu> iterable = menuDao.findAll().iterator();
        while (iterable.hasNext()) {
            menuList.add(iterable.next());
        }
        return menuList;
    }

    public boolean save(Menu menu) {
        menu.setId(RandomUtil.simpleUUID());
        menu.setIsShow(Constant.TRUE);
        menu.setCreateTime(DateUtil.date());

        Menu result = menuDao.save(menu);
        return true;
    }
}
